package com.nine.pesys.base;

import com.nine.pesys.model.entity.*;
import com.nine.pesys.model.service.*;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import net.sf.json.JsonConfig;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;

import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by etund on 2014/10/30.
 */
@SuppressWarnings("all")
public abstract class BaseAction<T>extends ActionSupport implements ModelDriven<T>,SessionAware {

    protected  List<T> list = new ArrayList<T>();

    /**
     * 分页数据
     */
    protected Integer pageNo = 1;
    protected Integer totalCount = 0;
    protected Integer pageSize = 3;


    protected String isBS;
    protected JsonConfig jsonConfig = new JsonConfig();


    protected List<Game> games = new ArrayList<Game>();
    protected List<User> users = new ArrayList<User>();
    protected List<Equipment> equipments = new ArrayList<Equipment>();
    protected List<EquipmentDetail> equipmentDetails = new ArrayList<EquipmentDetail>();
    protected List<EquipmentImformation> equipmentImformations = new ArrayList<EquipmentImformation>();
    protected List<SportField> sportFields = new ArrayList<SportField>();
    protected List<SportFieldDetail> sportFieldDetails = new ArrayList<SportFieldDetail>();
    protected List<FileInformation> fileInformations = new ArrayList<FileInformation>();
    protected List<Role> roles = new ArrayList<Role>();
    protected List<Announcement> announcements = new ArrayList<Announcement>();

    @Autowired
    protected UserService userService;
    @Autowired
    protected GameService gameService;
    @Autowired
    protected EquipmentService equipmentService;
    @Autowired
    protected EquipmentDetailService equipmentDetailService;
    @Autowired
    protected EquipmentImformationService equipmentImformationService;
    @Autowired
    protected SportFieldService sportFieldService;
    @Autowired
    protected SportFieldDetailService sportFieldDetailService;
    @Autowired
    protected FieldInformationService fieldInformationService;
    @Autowired
    protected RoleService roleService;
    @Autowired
    protected AnnouncementService announcementService;

    protected  Map<String ,Object> session;
    protected   T model;
    public BaseAction() {
        try {
            ParameterizedType pt = (ParameterizedType)this.getClass().getGenericSuperclass();
            Class<T> clazz = (Class<T>)pt.getActualTypeArguments()[0];
            model = clazz.newInstance();
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }
    @Override
    public T getModel() {
        return model;
    }

    @Override
    public void setSession(Map<String, Object> session) {
                this.session = session;
    }

    public String getIsBS() {
        return isBS;
    }

    public void setIsBS(String isBS) {
        this.isBS = isBS;
    }

    public Integer getPageNo() {
        return pageNo;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}

